import 'package:FlutterStudy/demo/mine/CircleImage.dart';
import 'package:FlutterStudy/demo/mine/MineController.dart';
import 'package:FlutterStudy/demo/mine/Timage.dart';
import 'package:FlutterStudy/demo/mine/bg_detail.dart';
import 'package:FlutterStudy/utils/splash.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../generated/l10n.dart';

void main() {
  runApp(
    MaterialApp(
      localizationsDelegates: {S.delegate},
      home: MinePage(),
      theme: ThemeData(
        textTheme: TextTheme(
          bodyMedium: TextStyle(
            // fontFamily: 'Alimama FangYuanTi VF',
            decoration: TextDecoration.none,
            color: Colors.white,
            fontWeight: FontWeight.w800,
          ),
          bodySmall: TextStyle(
            // fontFamily: 'Alimama FangYuanTi VF',
            decoration: TextDecoration.none,
            color: Colors.white,
          ),
        ),
      ),
    ),
  );
}

class MinePage extends StatefulWidget {
  @override
  _MinePageState createState() {
    return _MinePageState();
  }
}

class _MinePageState extends State<MinePage> with Splash {
  String bg =
      "https://img0.baidu.com/it/u=1050291296,624435734&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500";

  MineController _mineController = Get.put(MineController());

  @override
  void initState() {
    super.initState();
    hideScreen();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 4,
      child: NestedScrollView(
        headerSliverBuilder: (context, innerBoxIsScrolled) {
          return [
            SliverAppBar(
              title: Text('Collapsed Title'), // 这是折叠后固定在顶部的标题
              floating: false,
              pinned: true,
              expandedHeight: 620,
              flexibleSpace: FlexibleSpaceBar(
                title: Text('Expanded Title'), // 展开时显示的标题
                collapseMode: CollapseMode.pin,
                background: Stack(
                  children: [
                    _bulidBgImage(),
                    Obx(
                      () => Text(
                        // 只有这个Text会在count变化时重建
                        'You have pushed the button this many times: ${_mineController.bg}',
                        style: Theme.of(context).textTheme.bodyMedium,
                      ),
                    ),
                    _bulidUserDetail(),
                  ],
                ),
              ),
              bottom: TabBar(
                tabs: [
                  Tab(text: '作品'),
                  Tab(text: '私密'),
                  Tab(text: '收藏'),
                  Tab(text: '喜欢'),
                ],
              ),
            ),
          ];
        },
        body: TabBarView(
          children: [
            Container(width: double.infinity, height: 100,color: Colors.yellow,),
            SingleChildScrollView(
              child: Container(width: double.infinity, height: 300,color: Colors.red),
            ),
            SingleChildScrollView(
              child: Container(width: double.infinity, height: 300),
            ),
            SingleChildScrollView(
              child: Container(width: double.infinity, height: 300),
            ),
          ],
        ),
      ),
    );
  }

  _bulidBgImage() {
    return GestureDetector(
      onTap: _goBgDetail,
      /* child: FadeInImage.assetNetwork(
        placeholder: Assets.assetsImagesPic1,
        image: bg,
        height: 200,
        width: double.infinity,
        fit: BoxFit.cover,
      ),*/
      // child: TImage(bg, double.infinity, 200),
      child: TImage(bg, double.infinity, 200),
    );
  }

  Future<void> _goBgDetail() async {
    String? selectPath =
        await Navigator.of(context).push(
              ModalBottomSheetRoute(
                builder: (context) => BgDetail(originPath: bg),
                isScrollControlled: true,
              ),
            )
            as String?;
    if (selectPath != null) {
      bg = selectPath;
      _mineController.bg = selectPath;
      /*   setState(() {

      });*/
    }
  }

  _bulidUserDetail() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Padding(
          padding: const EdgeInsets.only(top: 150),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              const SizedBox(width: 10),
              CircleImage(
                width: 70,
                url:
                    "https://img1.baidu.com/it/u=2172818577,3783888802&fm=253&app=138&f=JPEG?w=800&h=1422'",
                height: 70,
                radius: 50,
                mBorder: const Border.fromBorderSide(
                  BorderSide(color: Colors.white),
                ),
              ),
              const SizedBox(width: 10),

              Flexible(
                child: Column(
                  children: [
                    const Text(
                      "86868686868686868686868686",
                      style: TextStyle(
                        fontSize: 10,
                        fontWeight: FontWeight.bold,
                        color: Colors.black,
                        decoration: TextDecoration.none,
                      ),
                    ),
                    Text(
                      S.of(context).helloWorld,
                      style: const TextStyle(
                        fontSize: 10,
                        decoration: TextDecoration.none,
                      ),
                    ),
                  ],
                ),
              ),
              Container(width: 1, height: 33, color: Colors.white),

              Expanded(
                child: Column(
                  children: [
                    const Text(
                      "86",
                      style: TextStyle(
                        fontSize: 10,
                        fontWeight: FontWeight.bold,
                        color: Colors.black,
                        decoration: TextDecoration.none,
                      ),
                    ),
                    Text(
                      "关注",
                      style: const TextStyle(
                        fontSize: 10,
                        decoration: TextDecoration.none,
                      ),
                    ),
                  ],
                ),
              ),
              Container(width: 1, height: 33, color: Colors.white),
              Flexible(
                fit: FlexFit.loose,
                child: Column(
                  children: [
                    const Text(
                      "86868686868686868686868686",
                      style: TextStyle(
                        fontSize: 10,
                        fontWeight: FontWeight.bold,
                        color: Colors.black,
                        decoration: TextDecoration.none,
                      ),
                    ),
                    Text(
                      S.of(context).helloWorld,
                      style: const TextStyle(
                        fontSize: 10,
                        decoration: TextDecoration.none,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
        const Padding(
          padding: EdgeInsets.only(top: 10, left: 10),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "姓名",
                style: TextStyle(
                  fontSize: 10,
                  fontWeight: FontWeight.bold,
                  color: Colors.black,
                  decoration: TextDecoration.none,
                ),
              ),
              Text(
                "个性签名",
                style: TextStyle(
                  fontSize: 10,
                  fontWeight: FontWeight.bold,
                  color: Colors.black,
                  decoration: TextDecoration.none,
                ),
              ),
            ],
          ),
        ),
        Container(
          height: 1,
          width: double.infinity,
          color: Color.fromRGBO(23, 34, 34, 1),
          margin: EdgeInsets.only(left: 10, right: 10, top: 12),
        ),
        ElevatedButton(onPressed: _follow, child: Text("+关注")),
        FilledButton(
          onPressed: _follow,
          child: Text("+关注"),
          style: ButtonStyle(
            backgroundColor: WidgetStatePropertyAll<Color>(Colors.blue),
            foregroundColor: WidgetStatePropertyAll<Color>(Colors.white),
            shape: WidgetStatePropertyAll<RoundedRectangleBorder>(
              RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(1.0), // 设置圆角半径
              ),
            ),
          ),
        ),
      ],
    );
  }

  _buildTab() {
    return TabBarView(children: []);
  }

  void _follow() {}
}
